package com.yhp.servlet;

import com.yhp.service.impl.StudentService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;

@WebServlet(urlPatterns = "/Educational/student/finddelid")
public class FindDeletIdServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //1.获取id值
        int id = Integer.parseInt(req.getParameter("sid"));
        //2.调取service。通过id进删除
        int zt = StudentService.deletStudent(id);
        //3.跳转页面刷新
        resp.setContentType("text/html;charset=utf-8");
        PrintWriter writer = resp.getWriter();
        if (zt>0){
            writer.println("<script>alert('删除成功！');location.href='/Educational/student/getStudentList';</script>");
        }else {
            writer.println("<script>alert('删除失败！');location.href='/Educational/student/getStudentList';</script>");
        }
    }
}
